//
//  KoiSync.swift
//  KoiAccounting
//
//  Created by 纪洪文 on 18.04.25.
//

import Foundation
class KoiSync {
    
    static let standard = KoiSync()
    
    private let bookSync = KoiBookSync()
    private let categorySync = KoiCategorySync()
    private let detailSync = KoiDetailSync()
    
    // 全部更新，包括账本，类别，记账明细
    func syncFull() {
        if KoiAccountingUserManager.standard.isTrail() {
            return
        }
        DispatchQueue.global(qos: .background).async {
            let bookSynced = self.bookSync.sync()
            logger.info("book sync finish \(bookSynced)")
            let categorySynced = self.categorySync.sync()
            logger.info("category sync finish \(categorySynced)")
            let detailSynced = self.detailSync.sync()
            logger.info("detail sync finish \(detailSynced)")
            // 同步数据完成，发送通知，更新首页
            KoiEvent.homeReload.send()
        }
    }
}
